package com.jidong.test_springboot.service;

import java.util.Set;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jidong.test_springboot.dao.UserDao;
import com.jidong.test_springboot.entity.User;

import lombok.extern.slf4j.Slf4j;

@Component
@Slf4j
public class UserService {
	
	@Autowired
	private UserDao userDao;
	
	@Cacheable(value="default",key="'role::'+#uname")
	public Set<String> selectRoleByUname(String uname){
		log.info("读取数据库，获取角色");
		return userDao.selectRoleByUname(uname);
	}
	
	@Cacheable(value="default",key="'permission::'+#uname")
	public Set<String> selectPermissionByUname(String uname){
		log.info("读取数据库，获取权限");
		return userDao.selectPermissionByUname(uname);
	}
	
	public User selectUserByUnamePwd(String username, String password) {
		// eq的key是uname和pwd 来自数据库的字段
		return userDao.selectOne(new QueryWrapper<User>().eq("uname", username).eq("pwd", password));
		
	}
	
}
